package com.unytech.project.web.action.system;

import java.io.IOException;
import java.io.PrintWriter;

import com.opensymphony.xwork2.Action;
import com.unytech.project.entity.system.PermissionGroup;
import com.unytech.project.service.system.PermissionGroupService;
import com.unytech.project.service.system.impl.PermissionGroupServiceImpl;
import com.unytech.project.utils.PermissionUtil;
import com.unytech.project.web.action.BaseAction;

public class PermissionGroupAction extends BaseAction {
	private PermissionGroup permissiongroup = new PermissionGroup();
	
	PermissionGroupService permissionGroupService = new PermissionGroupServiceImpl();
	
	public String listAction() {
		
		
		return "permgrouplist";
	}
	
	public String addAction() {

		return "permgroupadd";	
	}
	
	public String getTreeXmlDataAjax() {
//		String permString = PermissionUtil.getXMLString().replace("\n\t", "").replace("\"", "\'").toString();
		String permString = PermissionUtil.getXMLString();
		//要对permString进行去空格，去回车换行处理
		//permString.replaceAll(regex, replacement)
		//permString.replace(10, 32);
		System.out.println("得到的权限XML字符串：" + permString);
		getResponse().setContentType("text/xml; charset=UTF-8");
		getResponse().setHeader("Cache-Control","no-cache");
		try {
			PrintWriter out = getResponse().getWriter();
			out.write(permString);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			return Action.ERROR;
		}   
//		OutputFormat format = OutputFormat.createCompactFormat();
		//去掉xml头   
		//format.setSuppressDeclaration(true);   
		//format.isPadText();   
//		format.setEncoding("UTF-8");   
//		XMLWriter writer = new XMLWriter(out, format);
//		InputStream inputstream = this.getClass().getResourceAsStream(filename);
//		SAXReader reader = new SAXReader();
//		Document document = reader.read(inputstream);
//		writer.write(document);   
//		writer.flush();  
//		writer.close(); 
		
		return null;
	}
	
	public String dealAdd() {

		return "message";
	}
	
	public String dealUpdate() {
		
		return "";
	}
	
	public String dealDelete() {
		
		return "";
	}
	
	
	
	public String getPermgroupname() {
		return this.permissiongroup.getPermgroupname();
	}

	public void setPermgroupname(String permgroupname) {
		this.permissiongroup.setPermgroupname(permgroupname);
	}

	public void setPermissionsids(String permissionsid) {
		this.permissiongroup.setPermgroupid(permissionsid);
	}
	public void setPermgroupintro(String permgroupintro) {
		this.permissiongroup.setPermgroupinfor(permgroupintro);
	}

	public String getPermgroupintro() {
		return this.permissiongroup.getPermgroupinfor();
	}
}
